using System;
using System.IO;
using CommandSystem;
using RgCore.Modules;

namespace RgCore.Commands.ModuleCommands
{
    public class Load : ICommand
    {
        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            if (!sender.CheckPermission(PlayerPermissions.ServerConsoleCommands))
            {
                response = "你没有权限执行此命令";
                return false;
            }

            if (File.Exists(Path.Combine(ModuleManager.SubPluginPath, $"{arguments.At(0)}.dll")))
            {
                ModuleManager.LoadPlugin(Path.Combine(ModuleManager.SubPluginPath, $"{arguments.At(0)}.dll"),
                    true);
                response = "加载成功！";
                return true;
            }

            response = "未找到此文件！";
            return false;
        }

        public string Command { get; } = "load";
        public string[] Aliases { get; } = Array.Empty<string>();
        public string Description { get; } = "加载一个插件";
    }
}